//
//  ZhuBoInformationViewController.m
//  喜马拉雅FM
//
//  Created by dllo on 16/3/3.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#import "ZhuBoInformationViewController.h"

#import "NetworkHandlerBlock.h"
#import "CellForTypeOfDetail.h"
#import "ItemVC3.h"

#import "ZhuBoHeadView.h"

#import "ModelForSecendVC.h"

@interface ZhuBoInformationViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) NSMutableDictionary *dicForZhuBoInformation;
@property (nonatomic, retain) NSMutableArray *arrForZhuBoList;

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) ZhuBoHeadView *headView;



@end

@implementation ZhuBoInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self handleData];
    
   
    
}

- (void)handleData {

    self.dicForZhuBoInformation = [NSMutableDictionary dictionary];
    self.arrForZhuBoList = [NSMutableArray array];
    NSString *str = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/homePage?toUid=%@&device=android",self.stringUid];

    [NetworkHandlerBlock netWorkingWithURL:str completeHandle:^(NSURLResponse *response, NSData *data, id result) {

        [self.dicForZhuBoInformation setValuesForKeysWithDictionary:result];
   
        [self createTableView];
        
        
    }];
    
    NSString *strForListUrl = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/track/%@/1/30?device=android",self.stringUid];
    
    [NetworkHandlerBlock netWorkingWithURL:strForListUrl completeHandle:^(NSURLResponse *response, NSData *data, id result) {
        
        NSArray *tempArr = [result objectForKey:@"list"];
        for (NSDictionary *dic in tempArr) {

            ModelForSecendVC *model = [ModelForSecendVC alloc];
            
            [model setValuesForKeysWithDictionary:dic];
            [self.arrForZhuBoList addObject:model];
        }
        [self.tableView reloadData];
    }];
}



- (void)createTableView {

    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    self.headView = [[ZhuBoHeadView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 250)];
    [self.headView passDictionary:self.dicForZhuBoInformation];
 
    self.tableView.tableHeaderView = self.headView;
    
    
    [self.tableView registerClass:[CellForTypeOfDetail class] forCellReuseIdentifier:@"poolForCellTypeOfDetail"];
}

#pragma mark tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSLog(@"%lu",self.arrForZhuBoList.count);
    return self.arrForZhuBoList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    ModelForSecendVC *model = [self.arrForZhuBoList objectAtIndex:indexPath.row];
    CellForTypeOfDetail *cell = [tableView dequeueReusableCellWithIdentifier:@"poolForCellTypeOfDetail"];
    [cell passModelForZhuBo:model];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 100;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    
    // 此处创建的ModelForZhuBoList与ModelForSecendVC是一模一样的,因此此处将ModelForSecendVC代替了ModelForZhuBoList
    ModelForSecendVC *model = [self.arrForZhuBoList objectAtIndex:indexPath.row];
    ItemVC3 *player = [[ItemVC3 alloc]init];
    
    player.musicUrlString = model.playUrl64;
    player.model = model;
    player.arrForModel = self.arrForZhuBoList;
    
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:player];
    [self presentViewController:navi animated:YES completion:^{
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}



@end
